//
//  MainTabBar.swift
//  NSinaWeibo
//
//  Created by LoliQueen on 16/2/15.
//  Copyright © 2016年 LoliQueen. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

    //在布局子控件方法中 设置空间
    override func layoutSubviews() {
        super.layoutSubviews()
//        //查看子视图有哪些  一共四个UITabBarButton 通过层次视图也可以看到
//        print(subviews)
        
        
        //确定每一个UITabBarButton 的大小
        let w = self.bounds.width/5
        let h = self.bounds.height
        let rect = CGRect(x: 0, y: 0, width: w, height: h)
        
        //设置一个递增索引
        var index: CGFloat = 0
        
        //遍历子视图 获取UITabBarButton
        for subview in subviews {
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!){
            //设置frame
                subview.frame = CGRectOffset(rect, w * index, 0)
                //判断当index  多递增一次
                if index == 1{
                    index++
                }
            index++
            }
            
        }
        //设置加号按钮的位置
        plusBtn.frame = CGRectOffset(rect, w * 2, 0)
    }
   
    //懒加载
   lazy var plusBtn:UIButton = {
        let btn = UIButton()
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState:.Normal)
    btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState:.Highlighted)
    
    btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState:.Normal)
    btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState:.Highlighted)

    self.addSubview(btn)
    
    return btn
    }()
}
